package com.lee.sshclient.plugin;

import com.lee.sshclient.ShellClient;
import com.lee.sshclient.ShellClientContainer;
import org.apache.cordova.CallbackContext;

/**
 * Created by le on 2016/1/28.
 */
public class SSHConnectRunnable implements Runnable {

    private final ShellClient shellClient;
    private final CallbackContext callbackContext;


    public SSHConnectRunnable(ShellClient shellClient, CallbackContext callbackContext) {
        this.shellClient = shellClient;
        this.callbackContext = callbackContext;
    }

    @Override
    public void run() {
        try {
            shellClient.connect();
            shellClient.openChannel();
        } catch (Exception e) {
            e.printStackTrace();
            ((ShellOutputStream) shellClient.getReceive()).writerLineToClient(e.getMessage());
            shellClient.disconnect();
            callbackContext.error("连接失败: " + e.getMessage());
        }
    }
}
